﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mani.Common.Security;
using Niazi.CRM.Business.Model;
using System.Web.Services;

namespace Niazi.CRM.Web
{
    public partial class print_orders : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SecurityManager secManager = new SecurityManager();
            secManager.authProvider = new WebAuthorizationProvider();

            if (!secManager.IsActionPermitted("Orders_insert"))
            {
                Response.Redirect("~/access_denied.aspx?action_name=Orders_insert");
            }
        }

        [WebMethod]
        public static long[] GetOrders(string count)
        {
            int orderCount = -1;
            if (!Int32.TryParse(count, out orderCount))
            {
                throw new Exception("لطفا تعداد بارنامه ها برای ارسال به پرینتر را مشخص کنید");
            }

            CRMModelContainer db = new CRMModelContainer();
            List<Order> orders = db.Orders.OrderByDescending(o => o.Id).Take(orderCount).ToList();
            long[] result = orders.OrderBy(o => o.NewspaperId).Select(o => o.Id).ToArray();
            return result;
        }
    }
}